package com.zhihuishu.micro.course.log;

import com.zhihuishu.toolkit.log.LoggerTemplate;
import com.zhihuishu.toolkit.log.MDCInfoBuilder;

public class MDCLoggerUtil {

    //public static final Logger LOGGER =LoggerFactory.getLogger(MDCLoggerUtil.class);
    public static final   LoggerTemplate logger=LoggerTemplate.getInstance(MDCLoggerUtil.class);
    public static void saveLogger(String message,Long userId,LoggerCollectionEnum loggerCollectionEnum){
        try {
            StackTraceElement[] tmpElements = Thread.currentThread().getStackTrace();
            MDCInfoBuilder mdcInfoBuilder=MDCInfoBuilder.create();
            mdcInfoBuilder.setTableName("courseSservice",loggerCollectionEnum.getTableName()).
            setMethodName(tmpElements[2].getMethodName()).
            setModuleName(tmpElements[2].getClassName()).
            put("userId", userId==null?"0":userId.toString());
            logger.info(mdcInfoBuilder.build(), "{}", message);
        } catch (Exception e) {
            e.printStackTrace();
        }  
    }
    //加了一个courseId
    public static void saveLogger(String message,Long userId,LoggerCollectionEnum loggerCollectionEnum,Long courseId){
        try {
            StackTraceElement[] tmpElements = Thread.currentThread().getStackTrace();
            MDCInfoBuilder mdcInfoBuilder=MDCInfoBuilder.create();
            mdcInfoBuilder.setTableName("courseService",loggerCollectionEnum.getTableName()).
            setMethodName(tmpElements[2].getMethodName()).
            setModuleName(tmpElements[2].getClassName()).
            put("userId", userId==null?"0":userId.toString())
            .put("courseId",courseId==null?"0":courseId.toString());
            logger.info(mdcInfoBuilder.build(), "{}", message);
        } catch (Exception e) {
            e.printStackTrace();
        }     
    }
}
